<?php
use yii\helpers\Url;
$this->title = $isComplete ? '会员资料' : '完善会员资料';

if (preg_match('/^(852|853)/', $userInfo['mobile'])) {
    $mobile = substr($userInfo['mobile'], 0, 3) . '-' . substr($userInfo['mobile'], 3);
} elseif (preg_match('/^86/', $userInfo['mobile'])) {
    $mobile = substr($userInfo['mobile'], 0, 2) . '-' . substr($userInfo['mobile'], 2);
} else {
    $mobile = $userInfo['mobile'];
}
?>
    <div class="profile_container">
    <?php if ($isComplete) { ?>
        <!-- <div class="weui_cells_title waringColor">·请填写您的真实信息，有机会获得会员赠礼！</div> -->
    <?php } ?>
        <header class="info_header">
            <div class="logo-box">
            <img src="<?= Url::to('@web/jebsen/img/header.png')?>" alt="">          
            </div>
            <div style="text-align:center;color:red;position:relative;bottom:-1rem;">
               <p id="prompt_text"></p>
            </div>
        </header>
        <form action="<?= Url::to(['member/profile']) ?>" method="post" class="form_box" id="profile_box">
                <table class="view_profile" >
                    <tbody>
                    <tr class="list err_tr" >
                        <td ></td>
                        <td ></td>
                        <td class="input_box"  id="err_td1">  
                              
                        </td>
                    </tr>
                    <tr class="list">
                        <td class="icon_box"><img class="icon" src="<?= Url::to('@web/jebsen/img/i_user.png')?>" alt=""></td>
                        <td class="label_box"><label  class="td_label">姓&nbsp;&nbsp;<span class="require">*</span>:</label></td>
                        <td class="input_box" >
                            <div id="name_box" >
                                <input id="last_name" class="td_input" type="text" name="last_name" value="<?= isset($userInfo['last_name']) ? $userInfo['last_name'] : ''  ?>" placeholder="">
                                <!-- <span class="error_icon"><img src="<?= Url::to('@web/jebsen/img/error.png')?>" alt=""></span> -->
                            </div>
                        </td>
                    </tr>
                  
                    <tr class="list">
                        <td class="icon_box"><img class="icon" src="<?= Url::to('@web/jebsen/img/i_user.png')?>" alt=""></td>
                        <td class="label_box"><label  class="td_label">名&nbsp;&nbsp;<span class="require">*</span>:</label></td>
                        <td class="input_box"  >
                            <div id="firstname_box">
                            <input id="first_name" class="td_input" type="text" name="first_name" value="<?= isset($userInfo['first_name']) ? $userInfo['first_name'] : ''  ?>" placeholder="">
                            </div>
                        </td>
                    </tr>
                    <tr class="list">
                        <td class="icon_box"><img class="icon" src="<?= Url::to('@web/jebsen/img/i_sex.png')?>" alt=""></td>
                        <td class="label_box"><label  for="gender" class="td_label">称谓<span class="require">*</span>:</label></td>
                        <td class="input_box" >
                            <div id="sex_box">
                            <select class="td_input" type="text" id='msg_gender' name="gender" required>
                                <option value="先生" name="gender" <?php if($userInfo['gender'] == '先生'){echo 'selected';} ?>>先生</option>
                                <option value="女士" name="gender" <?php if($userInfo['gender'] == '女士'){echo 'selected';} ?>>女士</option>
                                <option value="小姐" name="gender" <?php if($userInfo['gender'] == '小姐'){echo 'selected';} ?>>小姐</option>
                            </select>
                            </div>
                        </td>
                    </tr>
                    <tr class="list">
                        <td class="icon_box"><img class="icon" src="<?= Url::to('@web/jebsen/img/i_tell.png')?>" alt=""></td>
                        <td class="label_box"><label class="td_label">电话<span class="require">*</span>:</label></td>
                        <td class="input_box">
                            <input id='iphone' readonly="readonly" class="td_input" name="mobile" type="text" value="<?= $mobile ?>" style="<?= isset($userInfo['mobile']) ? 'border:none;' : '';?>"  placeholder="请输手机号码">
                        </td>
                    </tr>
                    <!-- <tr id="mail_list"><td colspan=3></td></tr> -->
                    <tr class="list err_tr" >
                        <td ></td>
                        <td ></td>
                        <td class="input_box" id="err_td2">
                           
                               
                           
                        </td>
                    </tr>
                    <tr class="list">
                        <td class="icon_box"><img class="icon" src="<?= Url::to('@web/jebsen/img/i_mail.png')?>" alt=""></td>
                        <td class="label_box"><label class="td_label">邮箱：</label></td>
                        <td class="input_box" s>
                            <div id="mail_box">
                                <input id="email" class="td_input" type="email" name="email" value="<?= isset($userInfo['email'])?$userInfo['email']:""?>" style="border:none;" placeholder="输入您常用的电子邮箱">
                            </div>
                        </td>
                    </tr>
                    <tr class="list">
                        <td class="icon_box"><img class="icon" src="<?= Url::to('@web/jebsen/img/i_age.png')?>" alt=""></td>
                        <td class="label_box"><label class="td_label">年龄：</label></td>
                        <td class="input_box" >
                            <div id="age_box">
                                <select class="td_input" id='agegroup' name="agegroup">
                                    <option value="21岁以下" <?php if($userInfo['agegroup'] == '21岁以下'){echo 'selected';} ?>>21岁以下</option> 
                                    <option value="21-25" <?php if($userInfo['agegroup'] == '21-25'){echo 'selected';} ?>>21-25</option> 
                                    <option value="26-30" <?php if($userInfo['agegroup'] == '26-30'){echo 'selected';} ?>>26-30</option> 
                                    <option value="31-35" <?php if($userInfo['agegroup'] == '31-35'){echo 'selected';} ?>>31-35</option> 
                                    <option value="36-40" <?php if($userInfo['agegroup'] == '36-40'){echo 'selected';} ?>>36-40</option> 
                                    <option value="41-45" <?php if($userInfo['agegroup'] == '41-45'){echo 'selected';} ?>>41-45</option> 
                                    <option value="46-50" <?php if($userInfo['agegroup'] == '46-50'){echo 'selected';} ?>>46-50</option> 
                                    <option value="51-55" <?php if($userInfo['agegroup'] == '51-55'){echo 'selected';} ?>>51-55</option> 
                                    <option value="55岁以上" <?php if($userInfo['agegroup'] == '55岁以上'){echo 'selected';} ?>>55岁以上</option>
                                </select>
                            </div>
                        </td>
                    </tr>
                    <tr class="list">
                        <td class="icon_box"><img class="icon" src="<?= Url::to('@web/jebsen/img/i_birth.png')?>" alt=""></td>
                        <td class="label_box"><label class="td_label">生日：</label></td>
                        <td class="input_box" >
                        <div id="birth_box">
                                <select id="month" name="birth_mm">
                                    <option value="1">1月</option>
                                    <option value="2">2月</option>
                                    <option value="3">3月</option>
                                    <option value="4">4月</option> 
                                    <option value="5">5月</option> 
                                    <option value="6">6月</option>
                                    <option value="7">7月</option> 
                                    <option value="8">8月</option> 
                                    <option value="9">9月</option>
                                    <option value="10">10月</option>
                                    <option value="11">11月</option>
                                    <option value="12">12月</option>
                                </select>
                                <select id="day" name="birth_dd">
                                    <option value="1">1日</option>
                                    <option value="2">2日</option>
                                    <option value="3">3日</option>
                                    <option value="4">4日</option>
                                    <option value="5">5日</option>
                                    <option value="6">6日</option>
                                    <option value="7">7日</option>
                                    <option value="8">8日</option>
                                    <option value="9">9日</option>
                                    <option value="10">10日</option>
                                    <option value="11">11日</option>
                                    <option value="12">12日</option>
                                    <option value="13">13日</option>
                                    <option value="14">14日</option>
                                    <option value="15">15日</option>
                                    <option value="16">16日</option>
                                    <option value="17">17日</option>
                                    <option value="18">18日</option>
                                    <option value="19">19日</option>
                                    <option value="20">20日</option>
                                    <option value="21">21日</option>
                                    <option value="22">22日</option>
                                    <option value="23">23日</option>
                                    <option value="24">24日</option>
                                    <option value="25">25日</option>
                                    <option value="26">26日</option>
                                    <option value="27">27日</option>
                                    <option value="28">28日</option>
                                    <option value="29">29日</option>
                                    <option value="30">30日</option>
                                    <option value="31">31日</option>
                                </select>
                            </div>
                        </td>
                    </tr>
                    <tr class="list" >
                        <td class="icon_box" rowspan=3><img class="icon" src="<?= Url::to('@web/jebsen/img/i_add.png')?>" alt=""></td>
                        <td class="label_box" rowspan=3><label class="td_label">地区：</label></td>
                        <td class="input_box" >
                        <div id="province_box">
                            <input type="hidden" name="state" id="state">
                            <select class="td_input" id='cmbProvince' name="cmbProvince">
                            </select>
                        </div>    
                        </td>
                    </tr>
                    <tr class="list" >
                        <!-- <td class="icon_box"><img class="icon" src="<?= Url::to('@web/jebsen/img/i_add.png')?>" alt=""></td>
                        <td class="label_box"><label class="td_label">地区：</label></td> -->
                        <td class="input_box" >
                        <div id="city_box">
                            <input type="hidden" name="city" id="city">
                            <select class="td_input" id='cmbCity' name="cmbCity">
                            </select>
                        </div>    
                        </td>
                    </tr>
                    <tr class="list" >
                        <!-- <td class="icon_box"><img class="icon" src="<?= Url::to('@web/jebsen/img/i_add.png')?>" alt=""></td>
                        <td class="label_box"><label class="td_label">地区：</label></td> -->
                        <td class="input_box" >
                        <div id="district_box">
                            <input type="hidden" name="district" id="district">
                            <select class="td_input" id='cmbArea' name="cmbArea">
                            </select>
                        </div>    
                        </td>
                    </tr>
                    </tbody>
                </table>
                <div class="" id="save">
                    <input name="_csrf" type="hidden" id="_csrf" value="<?= Yii::$app->request->csrfToken ?>">
                    <input name="code" type="hidden" id="code" value="<?= isset($userInfo['code']) ? $userInfo['code'] : '' ?>">
                    <!-- <input type="submit" class="weui_btn weui_btn_primary" href="Usermsg" value="修改"> -->
                    <a id="sub_btn" type="submit" class="sub_btn" style="background-color:#2bb2e1;">提&nbsp;交</a>
                </div>
            </form>
            <!-- formDiv  end   lisa-->


    </div>
</div>
</div>

<script>
var mm="<?= $userInfo['birth_mm'] ?>";
var dd="<?= $userInfo['birth_dd'] ?>";
var state="<?= $state['name'] ?>";
var city="<?= $city['name'] ?>";
var district="<?= $district['name'] ?>";
</script>

<?php

$js = '
$("#sub_btn").click(function(){
    formtest();
   
})
$(function(){
    $("#month").find("[value=\'"+mm+"\']").prop("selected", "selected");
    $("#day").find("[value=\'"+dd+"\']").prop("selected", "selected");
    month_day("month","day");
    addressInit("cmbProvince", "cmbCity", "cmbArea", "", state, city, district);
})
';
$this->registerJs($js);
$this->registerJsFile(Url::to('@web/jebsen/js/month_day.js'), ['position' => '3']);
$this->registerJsFile(Url::to('@web/jebsen/js/address_name_code.js'), ['position' => '3']);
$this->registerJsFile(Url::to('@web/jebsen/js/address.js'), ['position' => '3']);

?>

<script>
    
         
    var formtest=function(){
        var name = document.getElementById("last_name");
        var firstname = document.getElementById("first_name");
        var email = document.getElementById("email");
        // var prompt_text = document.getElementById("prompt_text");
       
        var err_td1=document.getElementById("err_td1"); 
        var err_td2= document.getElementById("err_td2");
        var reg=/^\s*\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+\s*$/;
        var  name_val=name.value.trim();
        var firstname_val=firstname.value.trim();
        var email_val=email.value+"";
            email_val=email_val.trim();
        var reset=function(){
            err_td1.style.cssText="display:none";
            err_td2.style.cssText="display:none";   
            $(".input_box div").removeClass("error_box");
         }        
            reset();
         if(name_val==""){
        
            err_td1.style.cssText ="display:block";
            err_td1.innerHTML="您的姓不能为空";
            $("#name_box").addClass("error_box");
            name.focus();
         }else if(firstname_val==""){
            err_td1.style.cssText = "display:block";
            err_td1.innerHTML = "您的名不能为空";
            $("#firstname_box").addClass("error_box");
             firstname.focus();
         }else if(email_val==""){
            err_td2.style.cssText ="display:block";
            err_td2.innerHTML="您的邮箱不能为空";
            $("#mail_box").addClass("error_box");
            email.focus();
         }else if(!reg.test(email_val)){
            err_td2.style.cssText = "display:block";
            err_td2.innerHTML = "请输入正确格式的邮箱";
            $("#mail_box").addClass("error_box");
            email.focus();
         }
        else{             //通过以上格式验证，才能提交表单；
            $("form").submit();
         }
       
    }
    
</script>
